<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>map初步使用</title>
</head>
<body>
    <script>
        // 1.创建
        let map = new Map( [ 
            ["key","value"] , 
            [{a : 1},[1,2,3,4,5,6,7]],
            [123,"123"]
        ] );
        console.log(map);

        // 2.增
        map.set(["666"],789);
        console.log(map);

        // 3.删：无法直接以复杂数据类型为参数删除，要用变量存储复杂数据类型，再根据变量名删除
        /* let obj = {a : 1};
        let map = new Map( [ 
            ["key","value"] , 
            [obj,[1,2,3,4,5,6,7]],
            [123,"123"]
        ] );
        map.delete(obj);
        console.log(map); */

        // 4. 查
        // 4.1.1 遍历value
        map.forEach(item=>console.log(item));
        // 4.1.2
        for(let value of map.values()){
            console.log(value);
        }

        // 4.2 遍历key
        for(let key of map.keys()){
            console.log(key);
        }

        // 4.3 遍历数据
        for(let item of map.entries()){
            console.log(item);
        }


    </script>
</body>
</html>